package com.lovo.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspect {
    @Pointcut("execution(* com.lovo.service..*(..)) || execution(* com.lovo.dao..*(..))")
    public void setPointcut(){}

//    @Before("setPointcut()")
//    public void sayHello(){
//        System.out.println("say hello");
//
//    }
//    @After("setPointcut()")
//    public void sayBye(){
//        System.out.println("say bye");
//    }
//    @AfterThrowing("setPointcut()")
//    public void sayError(){
//        System.out.println("出错了");
//    }
    @Around("setPointcut()")
    public Object sayAround(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("进入方法：" + joinPoint.getSignature());
        Object obj = null;
        try {
            obj = joinPoint.proceed(joinPoint.getArgs());
        } catch (Throwable e) {
            System.out.println("出错了：" + joinPoint.getSignature());
            throw e;
        }
        System.out.println("退出方法：" + joinPoint.getSignature());
        return obj;
    }
}
